SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Apex

Apex static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your APEX code

  • All rules 56
  • Vulnerability1
  • Bug12
  • Security Hotspot3
  • Code Smell40
 
Tags
    Impact
      Clean code attribute
        1. Executing SOQL, SOSL or DML queries without sharing or with inherited sharing is security sensitive

           Security Hotspot
        2. Hard-coded credentials are security-sensitive

           Security Hotspot
        3. Using hardcoded IP addresses is security-sensitive

           Security Hotspot

        Executing SOQL, SOSL or DML queries without sharing or with inherited sharing is security sensitive

        intentionality - complete
        security
        Security Hotspot

          By default Apex code executes without checking permissions. Hence the code will not enforce field level security, sharing rules and user permissions during execution of Apex code in Triggers, Classes and Controllers. This creates the risk that unauthorized users may get access to sensitive data records or fields.

          It is possible to specify different level of sharing via the keywords "with sharing", "without sharing" or "inherited sharing". The last two should be used very carefully as they can create security risks.

          This rule raises an issue whenever a DML, SOSL or SOQL query is executed in a class marked as without sharing or inherited sharing.

          Ask Yourself Whether

          • this code gives access to or modifies restricted records.
          • this code may be executed by users who shouldn’t have access to those records.
          • if the class is marked as inherited sharing, it may be called by a class marked as without sharing.

          There is a risk if you answered yes to any of those questions.

          Recommended Secure Coding Practices

          • Use with sharing whenever possible.
          • Use without sharing only after checking that the code is not accessible to unauthorized users.
          • Use inherited sharing only when all calling without sharing classes are safe.

          Sensitive Code Example

          public without sharing class MyClass {
            List<List<SObject>> sList = [FIND 'TEST' IN ALL FIELDS
                                                RETURNING Case(Name), Contact(FirstName,LastName)]; // Sensitive
          }
          
          public inherited sharing class MyClass {
            List<Case> lstCases = new List<Case>();
            for(Case c:[SELECT Id, Status FROM Case WHERE Status = 'In Progress']){ // Sensitive
                c.Status = 'Closed';
                lstCasesToBeUpdated.add(c);
            }
            Update lstCasesToBeUpdated; // Sensitive
          }
          

          Compliant Solution

          public with sharing class MyClass { // Compliant
            List<Case> lstCases = new List<Case>();
            for(Case c:[SELECT Id FROM Case WHERE Status = 'In Progress']){
                // ...
            }
          }
          

          See

          • Using the with sharing, without sharing, and inherited sharing Keywords
            Available In:
          • SonarQube IdeCatch issues on the fly,
            in your IDE
          • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
          • SonarQube ServerAnalyze code in your
            on-premise CI
            Enterprise
            Edition
            Available Since
            9.1

          © 2008-2025 SonarSource SA. All rights reserved.

          Privacy Policy | Cookie Policy | Terms of Use